package com.teadent.dao;

import com.teadent.bean.Person;
import com.teadent.util.ConnectionFactory;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserLoginDaoImpl implements UserLoginDao {
    @Override
    public Person getLogin(Person person) {

        String sql="select * from person where userAccount='" +person.getUserAccount()
                +"' and userPassword='"+person.getUserPassword()+"'";
        Connection connection= ConnectionFactory.getConnection();
        PreparedStatement pre=null;
        ResultSet res=null;
        Person newPerson=null;
        try{
            pre=connection.prepareStatement(sql);

            res= pre.executeQuery();
            while (res.next()) {

                newPerson = new Person();
                /*private String userName;
    private String userId;
    private String userAccount;
    private String userPassword;
    private String userEmail;
    private String userSex;
    private String userOthername;
    private int userIdentify;*/
                newPerson.setUserName(res.getString("userName"));
                newPerson.setUserId(res.getString("userId"));
                newPerson.setUserAccount(res.getString("userAccount"));
                newPerson.setUserPassword(res.getString("userPassword"));
                newPerson.setUserIdentify(res.getInt("userIdentify"));
                newPerson.setUserSex(res.getString("userSex"));
                newPerson.setUserEmail(res.getString("userEmail"));
                newPerson.setUserOthername(res.getString("userOthername"));
            }
        }catch (SQLException throwables){
            throwables.printStackTrace();
        }

        return newPerson;

    }
}
